package com.nkzy.mapper;

import com.nkzy.pojo.Address;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper {

    @Insert("INSERT INTO address (id, user_id, province, city, town, mobile, street, contact, is_default, notes, deleted) " +
            "VALUES (#{id}, #{userId}, #{province}, #{city}, #{town}, #{mobile}, #{street}, #{contact}, #{isDefault}, #{notes}, #{deleted})")
    int insertAddress(Address address);

    @Delete("DELETE FROM address WHERE id = #{id}")
    int deleteAddressById(Long id);

    @Update("UPDATE address SET user_id = #{userId}, province = #{province}, city = #{city}, town = #{town}, " +
            "mobile = #{mobile}, street = #{street}, contact = #{contact}, is_default = #{isDefault}, notes = #{notes}, deleted = #{deleted} " +
            "WHERE id = #{id}")
    int updateAddress(Address address);

    @Select("SELECT * FROM address WHERE id = #{id}")
    Address selectAddressById(Long id);

    @Select("SELECT * FROM address")
    List<Address> selectAllAddresses(); // 新增方法：查询所有地址

    @Select("<script>" +
            "SELECT * FROM address WHERE id IN " +
            "<foreach item='id' index='index' collection='list' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<Address> selectAddressesByIds(List<Long> ids); // 新增方法：根据多个id查询地址
}